var urs =
{
	"urs"		:$.cookie("urs"),							//登录用户ID
	"pass_hex"	:$.cookie("pass_hex"),										
	"login_hex"	:$.cookie("login_hex"),							
	"msg"		:$.cookie("msg") || 0,							//消息数
	"login"		:function()									//是否登录
	{
		return ($.cookie("urs") 
					&& $.cookie("pass_hex") 
					&& $.cookie("login_hex")
				)?true:false;
	}
};
var DTCompare = function(o,el,c)
{
	if(typeof el != 'Object') el = _.e(el);
	if(o.value && el.value && ((c && o.value > el.value) || (!c && o.value < el.value)))
	{
		alert("提示:你输入的数据有误,请重试!");
		o.value = '';
	}
};
/**
 * @class oTime
 * 主要是时间相关的
 */
var oTime = 
{
	/**
	 * @private 私有
	 * @member  oTime
	 * 算两时间之间的差值 单位s(秒)
	 */
	Diff:function(begin,end)
	{
		var time=Math.floor((new Date()).getTime()/1000);
		begin = begin || time;
		end = end || time;
		return end - begin;
	},
	/**
	 * @member  oTime
	 * @param   Array arr   HTML element的数组
	 * @param   int   time  结束时间 s
	 * 算两时间之间的差值 单位s(秒)
	 */
	write:function(arr,time)
	{
		var tmp = this.Diff(0,time);
		if(tmp<=0) return false;
		var str = this.toStr(tmp);
		if (!(arr instanceof Array)) arr = [arr];
		for (var i=0;i<arr.length;i++)
		{
			tmp = _.e(arr[i]);
			if(typeof tmp == "object") 
				tmp.innerHTML = str;
		}
		return true;
	},
	/**
	 * @member  oTime
	 * @param   int   time  结束时间 s
	 * 把秒数转成string时间
	 */
	toStr:function(time)
	{
		return [Math.floor(time/86400),"天",Math.floor((time%86400)/3600),"小时",Math.floor((time%3600)/60),"分",(time%60),"秒"].join('');
	}
};
/**
 * @class checkbox 
 * checkbox 相关函数包
 */
var checkbox = 
{
	/**
	 * @param   Elem   HTML element
	 * checkbox 反选
	 */
	reverse:function(els)
	{
		if(els)
		{
			els['checked'] = els['checked']?false:true;
			for(var i=0;i<els.length;i++)els[i]['checked'] = els[i]['checked']?false:true;
		}
	},
	/**
	 * @param   Elem   HTML element
	 * @param   val    可选,选中 还是 取消
	 * checkbox 全选
	 */
	check:function(els,val)
	{
		if(els)
		{
			if(typeof val == "object") 
			{
				val = val['checked'];
			}else if(typeof val == "undefined")
			{
				val = true;
			}
			els['checked'] = val;
			for(var i=0;i<els.length;i++)els[i]['checked'] = val;
		}
	}	
}
var IM = function(o)
{
	var rs = [],fType=
	{
		msn:
		{
			n:"MSN",
			f:function(c)
			{
				var u = __scfg__.staticUrl || "http://www.pailego.com/static/";
				return c?'<a href="msnim:chat?contact='+c+'" target="_blank" ><img src="'+u+'imgs/im/msn.gif" border="0" align="absmiddle"></a>':'';
			}
		}, 
		yahoo:
		{
			n:"Yahoo通",
			f:function(c)
			{
				return c?'<a target="_blank" href="http://edit.yahoo.com/config/send_webmesg?.target='+c+'&.src=pg"><img border="0" align="absmiddle" src="http://opium3.msg.vip.mud.yahoo.com/online?u='+c+'&t=0&l=cn" alt="雅虎通在线状态"></a>':'';
			}
		},
		skype:
		{
			n:"Skype",
			f:function(c)
			{
				//http://skype.tom.com/help/skypebuttons/advanced.html
				return c?'<a target="blank" href="skype:'+c+'"><img src="http://mystatus.skype.com/smallicon/'+c+'"></a>':'';
			}
		},
		qq:
		{
			n:"腾讯QQ",
			f:function(c)
			{
				//http://imis.qq.com/webpresence/code.shtml
				return c?'<a target="blank" href="tencent://message/?uin='+c+'&Site=拍乐购&Menu=yes"><img border="0" src="http://wpa.paipai.com/pa?p=1:'+c+':17" alt="点击这里给我发消息"></a>':'';
			}
		}
	};
	for(var k in o)
	{
		f=fType[k];
		if(f.f)rs.push(f.f(o[k]));
	}
	return rs;	
}//end Im
/**
 * PageFunc
 */
var PageFunc = 
{
	/**
	 * 搜索
	 */
	searchForm:function()
	{
		var q=_.get("q");
		if(q)
		{
			var F,Kt = _.get("Kt");
			if(typeof document.searchForm == "object")
			{
				F = document.searchForm;
				if(Kt)F.Kt.value = Kt;
				F.q.value = q;
			}
			if(typeof document.searchFormFoot == "object")
			{
				F = document.searchFormFoot;
				if(Kt)F.Kt.value = Kt;
				F.q.value = q;
			}
		}
	},
	/**
	 * 页面头顶导航
	 */
	topNav:function()
	{
		var a = [],b=urs.login();
		a.unshift('<li><a><span>您好,'+(urs.urs?'<b>'+urs.urs+'</b>':'游客')+'！</span></a></li>');
		if(urs.urs)
		{
			if(b)
			{
				a.unshift('<li><a href="http://www.pailego2.com/urs/login.php?act=outLogin" class="orange"><span>[退出]</span></a></li>');
				a.unshift('<li><a href="http://www.pailego2.com/my/msg.php"><span>站内信</span></a></li>');
				a.unshift('<li><a href="http://www.pailego2.com/pay/"><span>支付帳號</span></a></li>');
				a.unshift('<li><a href="http://www.pailego2.com/my/fav.php"><span>收藏夹</span></a></li>');
			}else
			{
				a.unshift('<li><a href="http://www.pailego2.com/login.php" class="orange"><span>[重新登陸]</span></a></li>');
				a.unshift('<li><a href="http://www.pailego2.com/register.php"><span>免費注冊</span></a></li>');
			}
		}else
		{
			a.unshift('<li><a href="http://www.pailego2.com/login.php" class="orange"><span>[登陸]</span></a></li>');
			a.unshift('<li><a href="http://www.pailego2.com/register.php"><span>免費注冊</span></a></li>');
		}
		a.unshift('<li><a href="http://www.pailego2.com/search/"  class="bg"><span>我要買</span></a></li>');
		a.unshift('<li><a href="http://www.pailego2.com/my/sell.php"  class="bg"><span>我要賣</span></a></li>');
		//if(urs.urs)
		//{
			a.unshift('<li><a href="http://www.pailego2.com/my/"  class="bg"><span>我的拍樂</span></a></li>');
		//}else
		//{
		//	a.unshift('<li><a href="http://www.pailego2.com/register.php"><span>免費注冊</a></li>');
		//}
		a.unshift('<li><a href="http://bbs.pailego2.com/" target="_blank"  class="bg"><span>社区</span></a></li>');
		a.unshift('<li><a href="http://www.pailego2.com/help/" class="help"><span>幫助</span></a></li>');
		return a.join(' ');
	}	
}